package com.zhuss.team.publish;

import com.zhuss.bean.bo.team.publish.CreatePublishBo;
import com.zhuss.bean.bo.team.publish.DeletePublishBo;
import com.zhuss.bean.bo.team.publish.UnderPublishBo;
import com.zhuss.bean.bo.team.question.CreateQuestionBo;
import com.zhuss.bean.bo.team.question.DeleteQuestionBo;
import com.zhuss.bean.bo.team.question.UpdateQuestionBo;
import com.zhuss.common.OperateService;
import com.zhuss.common.Processor;
import com.zhuss.exception.WpsException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/26 12:55
 */
@Component("publishOperateService")
public class PublishOperateService implements OperateService<Void,Object> {

    @Autowired
    @Qualifier("publishCreate")
    private Processor<Object, CreatePublishBo> publishCreate;

    @Autowired
    @Qualifier("publishDelete")
    private Processor<Object, DeletePublishBo> publishDelete;

    @Autowired
    @Qualifier("publishUnder")
    private Processor<Object, UnderPublishBo> publishUnder;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Void create(Object o) throws WpsException {
        CreatePublishBo bo = (CreatePublishBo) o;
        publishCreate.process(bo);
        return null;
    }

    @Override
    public Void update(Object o) throws WpsException {
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Void delete(Object o) throws WpsException {
        DeletePublishBo bo = (DeletePublishBo) o;
        publishDelete.process(bo);
        return null;
    }

    @Transactional(rollbackFor = Exception.class)
    public Void under(Object o) throws WpsException {
        UnderPublishBo bo = (UnderPublishBo) o;
        publishUnder.process(bo);
        return null;
    }
}
